package com.zhijian.wharf.controller.web;

import com.zhijian.response.annotation.Response;
import com.zhijian.util.page.Page;
import com.zhijian.wharf.annotation.LogOperation;
import com.zhijian.wharf.entity.vo.request.VideoDeviceSaveOrUpdateVo;
import com.zhijian.wharf.entity.vo.request.VideoDeviceSearchVo;
import com.zhijian.wharf.entity.vo.response.VideoDeviceVo;
import com.zhijian.wharf.service.VideoDeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 视频设备 控制层
 *
 * @author auto
 * @version 1.0
 * @date 2024-07-10 13:59:25
 */
@Slf4j
@Controller
@Api(tags = "视频设备")
public class VideoDeviceController {

    @Autowired
    private VideoDeviceService service;

    /**
     * 新增
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/video/device")
    @ApiOperation("新增")
    @LogOperation("新增视频设备")
    public boolean insert(@RequestBody VideoDeviceSaveOrUpdateVo param) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        return service.save(param);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Response
    @DeleteMapping("/video/device/{id}")
    @ApiOperation("删除")
    @LogOperation("删除视频设备")
    public boolean delete(@PathVariable("id") Long id) {
        log.info("{} - {}| delete info", this.getClass().getSimpleName(), id);
        service.deleteById(id);
        return true;
    }

    /**
     * 修改
     *
     * @param id
     * @param param
     * @return
     */
    @Response
    @PutMapping("/video/device/{id}")
    @ApiOperation("修改")
    @LogOperation("修改视频设备")
    public boolean update(@PathVariable("id") Long id, @RequestBody VideoDeviceSaveOrUpdateVo param) {
        log.info("{} - {}| update info, {}", this.getClass().getSimpleName(), id, param);
        param.setId(id);
        return service.modify(param);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Response
    @GetMapping("/video/device/{id}")
    @ApiOperation("根据id查询")
    @LogOperation("查询视频设备详情")
    public VideoDeviceVo selectById(@PathVariable("id") Long id) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), id);
        return service.selectVoById(id);
    }

    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/video/device/page")
    @ApiOperation("分页查询")
    @LogOperation("分页查询视频设备")
    public Page<VideoDeviceVo> selectByCondition(@RequestBody(required = false) VideoDeviceSearchVo param) {
        if (param == null)
            param = VideoDeviceSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectPage(param);
    }

    /**
     * 列表查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/video/device/list")
    @ApiOperation("列表查询")
    @LogOperation("列表查询视频设备")
    public List<VideoDeviceVo> selectList(@RequestBody(required = false) VideoDeviceSearchVo param) {
        if (param == null)
            param = VideoDeviceSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectList(param);
    }

    /**
     * 批量删除
     *
     * @param idList
     * @return
     */
    @Response
    @DeleteMapping("/video/device/list")
    @ApiOperation("批量删除")
    public boolean delete(@RequestBody(required = false) List<Long> idList) {
        log.info("{} - {}| delete info", this.getClass().getSimpleName(), idList);
        service.deleteByIdList(idList);
        return true;
    }

    /**
     * 导入
     *
     * @param file
     * @return
     */
    @Response
    @PostMapping("/video/device/import")
    @ApiOperation("导入")
    public boolean importExcel(@ApiParam(name = "areaId", value = "区域ID") @RequestParam(value = "areaId") Long areaId,
                               MultipartFile file) {
        return service.importExcel(areaId, file);
    }

}